package kkk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.RoundStartedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Strafer moves.
 * 
 * @author Kyle Kakinami
 * 
 */
public class TestStraferMovement extends RobotTestBed {
  /** True if the robot moves. */
  boolean moved = true;
  double lastXPos;
  double lastYPos;

  /**
   * Specifies that SittingDuck and Strafer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,kkk.Strafer*";
  }

  /**
   * This test runs for 1 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 1;
  }

  /**
   * This gets robots starting position.
   * 
   * @param event details about event.
   */
  @Override
  public void onRoundStarted(RoundStartedEvent event) {
    IRobotSnapshot robot = event.getStartSnapshot().getRobots()[1];
    lastXPos = robot.getX();
    lastYPos = robot.getY();
  }

  /**
   * After each turn, check to see if we've moved from previous turn.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double xPos = robot.getX();
    double yPos = robot.getY();

    if (xPos != lastXPos || yPos != lastYPos) {
      moved = true;
    }
    lastXPos = xPos;
    lastYPos = yPos;
  }

  /**
   * After the battle, check to see that we've moved.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if Strafer moved", moved);
  }
}
